package org.dromara.web.controller.app;


import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.date.DateTime;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import org.dromara.common.core.domain.R;
import org.dromara.common.mongo.ChatAccusation;
import org.dromara.common.mongo.ChatAccusationMongoDao;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.web.controller.app.req.AddAccusationReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 *  新增举报
 *
 */
@RestController
@RequestMapping("/app/accusation")
public class AppAccusationController {

    @Autowired
    ChatAccusationMongoDao chatAccusationMongoDao;


    /**
     *  新增举报
     * @param req
     * @return
     */
    @Operation(
        requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
            content = @Content(
                schema = @Schema(implementation = AddAccusationReq.class)
            )
        )
    )
    @PostMapping("/add")
    public R<Void> add(@RequestBody @Validated AddAccusationReq req) {
        ChatAccusation chatAccusation = new ChatAccusation();
        chatAccusation.setCreateTime(DateTime.now());
        chatAccusation.setContent(req.getContent());
        chatAccusation.setSessionId(req.getSessionId());
        chatAccusation.setMessageId(req.getMessageId());
        chatAccusation.setUserId(LoginHelper.getUserId());
        chatAccusationMongoDao.save(chatAccusation);
        return R.ok();
    }



    @GetMapping("/getList")
    public R<List<ChatAccusation>> getList() {
        return R.ok(chatAccusationMongoDao.getList(LoginHelper.getAppUserId()));
    }




}
